﻿using UnityEngine;
using System.Collections;

public class Skill : MonoBehaviour, ISkillFlow {

	protected IPicker picker;
	protected ISkillTrigger trigger;
	protected Square caster;

#region virtual function
	protected virtual void InitSkillWithCaster()
	{
		return;
	}

	protected virtual ISkillTrigger CreateTrigger()
	{
		return new FadeTrigger ();
	}

	protected virtual IPicker CraetePicker()
	{
		return new FadePicker ();
	}
	
	protected virtual IHitAction CreateEffectAction()
	{
		return null;
	}

	// check is able to use
	public virtual bool IsSkillReady() {
		return false;
	}
#endregion
	// Use this for initialization
	void Start () {
		picker = CraetePicker ();
		picker.BindEventHandle (OnFindTarget);

		trigger = CreateTrigger ();
		trigger.BindHanle (OnTriggerReady);
	}
	
	// Update is called once per frame
	void Update () {

	}

	public void BindCaster(Square sqr) {
		caster = sqr;
		InitSkillWithCaster ();
	}

	public void SetSkillTrigger(ISkillTrigger trg)
	{
		trigger = trg;
	}

	public bool CastSkill()
	{
		if (false == IsSkillReady())
			return false;

		picker.EnableDetective (true);

		return false;
	}

	void OnFindTarget(object sender, MsgPicker msg)
	{
		if (msg.evt == EPickerEvt.eFindTarget)
			CreateEffectAction ();
	}

	void OnTriggerReady(object sender, SkillTriggerMsg msg)
	{
		if (sender != trigger)
			return;

		CastSkill ();
	}
}
